<?php
include './header.php';

$condition = "LIMIT {$offset},{$limit}";
$slogan = $db->selectAll('slogan', '*', $condition);
$count = $db->selectOne('slogan', 'COUNT(slogan_id)')[0];

$page_conf = [
    'current' => $current,
    'count' => $count,
    'limit' => $limit,
    'size' => $size,
    'class' => 'pagination'
];
$page_obj = Page::getInstance($page_conf);
$page = $page_obj->showpage();

// 删除
if (!empty($_GET['del_slogan_id'])) {
    $del_id = $_GET['del_slogan_id'];
    $del_cond = "WHERE slogan_id = $del_id";
    if ($db->delData('slogan', $del_cond)) {
        echo "<script>alert('删除成功！');window.location.href='slogan.php'</script>";
    } else {
        echo "<script>alert('删除失败！');window.location.href='slogan.php'</script>";
    }
}


// 批量删除
if ($_POST['del_all']) {
    for ($i = 0; $i < count($_POST['idarr']); $i++) {
        $del_cond = "WHERE slogan_id = {$_POST['idarr'][$i]}";

        if ($db->delData('slogan', $del_cond)) {
            echo "<script>alert('删除成功！');window.location.href='slogan.php'</script>";
        } else {
            echo "<script>alert('删除失败！');window.location.href='slogan.php'</script>";
        }
    }
}


?>

<!-- Start: Content -->
<section id="content">
    <div id="topbar" class="affix">
        <ol class="breadcrumb">
            <li><a href="#"><span class="glyphicon glyphicon-home"></span></a></li>
            <li class="if($ca_type == ''){echo 'active';}">标语管理</li>
        </ol>
    </div>
    <div class="container">

        <div class="row">
            <div class="col-md-12">
                <div class="panel">
                    <div class="panel-heading">
                        <div class="panel-title">修改标语</div>
                        <a href="slogan_add.php" class="btn btn-info btn-gradient pull-right"><span class="glyphicons glyphicon-plus"></span> 添加</a>
                    </div>
                    <form action="" method="post">
                        <div class="panel-body">
                            <h2 class="panel-body-title">互联网</h2>
                            <table class="table table-striped table-bordered table-hover dataTable">
                                <tr class="active">
                                    <th class="text-center" width="100"><input type="checkbox" id="checkall" class=""> 全选</th>
                                    <th width="150px">标题</th>
                                    <th width="150px">描述</th>
                                    <th>发布时间</th>
                                    <th width="150px">图片</th>
                                    <th width="200">操作</th>
                                </tr>
                                <?php foreach ($slogan as $val) { ?>
                                    <tr class="success">
                                        <td class="text-center"><input type="checkbox" value="<?php echo $val['slogan_id']; ?>" name="idarr[]" class="cbox"></td>
                                        <td><?php echo $val['slogan_title']; ?></td>
                                        <td><?php echo $val['slogan_desc']; ?></td>
                                        <td><?php echo date('Y-m-d', $val['slogan_time']); ?></td>
                                        <td><img src="<?php echo $val['slogan_thumb']; ?>" alt=""></td>
                                        <td>
                                            <div class="btn-group">
                                                <a href="slogan_edit.php?slogan_id=<?php echo $val['slogan_id']; ?>" class="btn btn-default btn-gradient"><span class="glyphicons glyphicon-pencil"></span></a>
                                                <a onclick="return confirm('确定要删除吗？');" href="slogan.php?del_slogan_id=<?php echo $val['slogan_id']; ?>" class="btn btn-default btn-gradient dropdown-toggle"><span class="glyphicons glyphicon-trash"></span></a>
                                            </div>
                                        </td>
                                    </tr>
                                <?php } ?>
                            </table>

                            <div class="pull-left">
                                <button type="submit" class="btn btn-default btn-gradient pull-right delall" name="del_all" value="del_all"><span class="glyphicons glyphicon-trash"></span></button>
                            </div>

                            <?php echo $page; ?>

                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</section>
<!-- End: Content -->
</div>
<!-- End: Main -->
</body>

</html>